package com.niuxiaofa.newlaw.adapter;

import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.niuxiaofa.newlaw.Bean.AreaCodeBean;
import com.niuxiaofa.newlaw.Bean.DemandTagsBean;
import com.niuxiaofa.newlaw.R;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;


public class AreaAdapter extends RecyclerView.Adapter<AreaAdapter.ViewHolder> {
    public List<AreaCodeBean.DataDTO> listEntities;
    AreaAdapter.Onclick onclick;

    int postion = 0;

    public AreaAdapter(List<AreaCodeBean.DataDTO> newsList, AreaAdapter.Onclick onclick) {
        this.onclick = onclick;
        this.listEntities = newsList;
    }


    @Override
    public AreaAdapter.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_text, viewGroup, false);
        AreaAdapter.ViewHolder viewHolder = new AreaAdapter.ViewHolder(view);


        return viewHolder;
    }

    @Override
    public void onBindViewHolder(AreaAdapter.ViewHolder viewHolder, int i) {

        viewHolder.text.setText(listEntities.get(i).getCountry() +"" + listEntities.get(i).getPrefix());
        viewHolder.linear.setOnClickListener(e -> {
            onclick.onclick(i);
        });
    }

    @Override
    public int getItemCount() {
        return listEntities.size();
    }

    public interface Onclick {

        void onclick(int c);

    }

    static class ViewHolder extends RecyclerView.ViewHolder {


        @BindView(R.id.text)
        TextView text;

        @BindView(R.id.linear)
        LinearLayout linear;

        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
